package com.tduck.cloud.datav.service.impl;


import cn.hutool.core.util.StrUtil;
import com.tduck.cloud.datav.request.ChartDataRequest;
import com.tduck.cloud.datav.service.BaseChartDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 获取图表数据
 */
@Service
public class ChartDataService {

    @Autowired
    private Map<String, BaseChartDataService> chartDataServiceMap;

    /**
     * 获取图表数据
     *
     * @param request 请求
     * @return
     */
    public Map<String, Object> getChartData(ChartDataRequest request) {
        // 首字母小写
        String chartType = StrUtil.lowerFirst(request.getChartType());
        BaseChartDataService baseChartDataService = chartDataServiceMap.get(chartType + "ChartDataService");
        if (null != baseChartDataService) {
            return baseChartDataService.getChartData(request);
        } else {
            return chartDataServiceMap.get("defaultChartDataService").getChartData(request);
        }
    }
}
